package com.zdgcc.site.util;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UserFilter implements Filter {
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain fc) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) req;
		HttpServletResponse response = (HttpServletResponse) resp;
		try {
			String uri = ((HttpServletRequest) req).getRequestURI();
			System.out.println(uri);
			uri = uri.replace("/ZhengDianSite/", "");
			System.out.println(uri);
			if (uri.endsWith("LoginServlet") || uri.endsWith("TestServlet") || uri.endsWith("jsp") || uri.endsWith("jpg") || uri.endsWith("js") || uri.endsWith("css")) {
				fc.doFilter(request, response);
			} else {
				RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
				dispatcher.forward(request, response);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void init(FilterConfig arg0) throws ServletException {

	}

	public void destroy() {

	}
}
